library(tidyverse)
library(broom)
library(kableExtra)
library(scales)
library(dplyr)
library(mclogit)


load("national.Rds")
load("california.Rds")



### 
#TABLE1: frequency of jobs
###
dflist = list(national_sample %>% 
  group_by(label_1) %>% 
  summarise(n = n()) %>% 
  mutate(Freq = (n/sum(n)), pct = percent(Freq)) %>% 
  arrange(desc(Freq)) %>% 
  dplyr::select(-Freq) %>% 
  rename(label = label_1),
  
  california %>% 
  filter(ELECTED %in% c(1,2)) %>% 
  group_by(label) %>% 
  summarise(n = n()) %>% 
  mutate(Freq = (n/sum(n)), pct = percent(Freq)) %>% 
  arrange(desc(Freq)) %>% 
  dplyr::select(-Freq),
  

  california %>% 
  filter(ELECTED == 1) %>% 
  group_by(label) %>% 
  summarise(n = n()) %>% 
  mutate(Freq = (n/sum(n)), pct = percent(Freq)) %>% 
  arrange(desc(Freq)) %>% 
  dplyr::select(-Freq),
  

  california %>% 
  filter(ELECTED == 2) %>% 
  group_by(label) %>% 
  summarise(n = n()) %>% 
  mutate(Freq = (n/sum(n)), pct = percent(Freq)) %>% 
  arrange(desc(Freq)) %>% 
  dplyr::select(-Freq))




#Table 1 latex
dflist[2:4] %>% 
  reduce(full_join, by='label') %>% 
  kableExtra::kbl(align = 'l',
                  digits = 2,
                  col.names = c("Category", "n", "% of Sample", "n", "% of Sample", "n", "% of Sample"),
                  format = "latex") %>% 
  kableExtra::kable_styling() %>% 
  add_header_above(c(" " = 1, "CA Cities (full)" = 2, "CA Cities (elected)" = 2, "CA Cities (unelected)" = 2))

